import {Config} from "../Config";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LoadingScene extends cc.Component {
    @property(cc.ProgressBar)
    progressBar = null;
    @property(cc.Label)
    precentLabel = null;

    onLoad(){
        console.log(cc.winSize);

        let self = this;
        self.progressBar.progress = 0;
        self.precentLabel.string = "0%";
        let date = new Date().getTime();
        (<any>cc.loader).onProgress = function (completedCount, totalCount, item) {
            //console.log("item",Math.floor(100 * completedCount / totalCount) + "%","time",(new Date().getTime()-date)/1000);
            if (self.precentLabel) {
                self.precentLabel.string = Math.floor(100 * completedCount / totalCount) + "%";
            }
            if(self.progressBar){
                self.progressBar.progress = completedCount / totalCount;
            }
        };
        cc.find("健康游戏忠告",this.node).active = Config.NEXT_SCENE == "LobbyScene";
        cc.director.loadScene(Config.NEXT_SCENE);
    }

    onDestroy(){
        (<any>cc.loader).onProgress = null;
    }
}
